package com.flyme.module.base.provider.service.impl;

import cn.hutool.core.date.DateUtil;
import com.flyme.core.base.supper.service.impl.BaseServiceImpl;
import com.flyme.module.base.client.entity.SysBuyrecord;
import com.flyme.module.base.provider.mapper.SysBuyrecordMapper;
import com.flyme.module.base.provider.service.SysBuyrecordService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: zyf
 * @date: 2018/10/24 16:33
 * @description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysBuyrecordServiceImpl extends BaseServiceImpl<SysBuyrecordMapper, SysBuyrecord> implements SysBuyrecordService {

    /**
     * 根据用户查询是否购买测评
     */
    public Integer findByUser(Long accountInfoId){
        return count(q().eq("accountInfoId", accountInfoId).ge("expireTime", DateUtil.now()));
    }

    /**
     * 根据用户查询购买的测评
     */
    public SysBuyrecord getByUser(Long accountInfoId){
        return getOne(q().eq(true, "accountInfoId", accountInfoId).ge(true,"expireTime", DateUtil.now()), false);
    }

    /**
     * 查询用户能力测评
     */
    public SysBuyrecord getByUser2(Long accountInfoId){
        return getOne(q().eq(true, "accountInfoId", accountInfoId),false);
    }

}
